//
//  WeekDayCollectionViewCell.m
//  TableTest
//
//  Created by 众拳科技 on 2017/11/10.
//  Copyright © 2017年 众拳科技. All rights reserved.
//

#import "WeekDayCollectionViewCell.h"

@interface WeekDayCollectionViewCell()



@end

@implementation WeekDayCollectionViewCell

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        UIView *bgView = [[UIView alloc] init];
        [self addSubview:bgView];
        self.bgView = bgView;
        
        /**
         排课对勾
         */
        UIImageView *teachImageView = [[UIImageView alloc] init];
        teachImageView.image = [UIImage imageNamed:@"icn_chooes"];
        [self addSubview:teachImageView];
        self.teachImageView = teachImageView;
        
        /**
         课程名字
         */
        UILabel *classNameLabel = [[UILabel alloc] init];
        classNameLabel.font = SmallFont;
        classNameLabel.lineBreakMode = NSLineBreakByCharWrapping;
        classNameLabel.numberOfLines = 0;
        classNameLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:classNameLabel];
        self.classNameLabel = classNameLabel;
        
        /**
         场地名字
         */
        UILabel *placeNameLabel = [[UILabel alloc] init];
        placeNameLabel.font = SmallFont;
        placeNameLabel.lineBreakMode = NSLineBreakByCharWrapping;
        placeNameLabel.numberOfLines = 0;
        placeNameLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:placeNameLabel];
        self.placeNameLabel = placeNameLabel;
        
        [self setConstraints];
        
    }
    
    return self;
}

-(void)setConstraints{
    
    [self.bgView mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.edges.mas_equalTo(self);
    }];
    
    [self.teachImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.center.mas_equalTo(self);
    }];
    
    [self.classNameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.mas_equalTo(self);
        
        make.width.mas_equalTo(self);
        
        make.top.mas_equalTo(self).offset(10);
    }];
    
    [self.placeNameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(self);
        
        make.width.mas_equalTo(self);
        
        make.bottom.mas_equalTo(self).offset(-10);
    }];
}


-(void)setRow:(NSInteger)row{
    
    _row = row;
    
    [self.topLayer removeFromSuperlayer];
    
    [self.rightLayer removeFromSuperlayer];
    
    [self.bottomLayer removeFromSuperlayer];
    
    self.topLayer = nil;
    self.rightLayer = nil;
    self.bottomLayer = nil;
    
    
    self.topLayer =  [CALayer layer];
    self.rightLayer =  [CALayer layer];
    self.bottomLayer =  [CALayer layer];
    
    if (self.row % 8 == 0) {
        
        self.rightLayer.frame = CGRectMake(self.frame.size.width - 1, 0, 1.0, self.frame.size.height);
        
        self.rightLayer.backgroundColor = BackGroundColor.CGColor;
        
        [self.layer addSublayer:self.rightLayer];
        
        return;
    }
    
    self.topLayer.frame = CGRectMake(0.0f, 0.0f, self.frame.size.width, 1.0);
    self.topLayer.backgroundColor = BackGroundColor.CGColor;
    [self.layer addSublayer:self.topLayer];
    
    
    self.rightLayer.frame = CGRectMake(self.frame.size.width - 1, 0, 1.0, self.frame.size.height);
    self.rightLayer.backgroundColor = BackGroundColor.CGColor;
    [self.layer addSublayer:self.rightLayer];
    
    self.bottomLayer.frame = CGRectMake(0.0f, self.frame.size.height, self.frame.size.width, 1.0);
    self.bottomLayer.backgroundColor = BackGroundColor.CGColor;
    [self.layer addSublayer:self.bottomLayer];
}


-(void)setBetwCount:(NSInteger)betwCount{
    
    _betwCount = betwCount;
    
    self.backgroundColor = [UIColor whiteColor];
    
    if (betwCount > 0 && betwCount <=6) {
        
        if (self.row % 8 == betwCount + 1) {
            
            self.backgroundColor = CSColorFromRGB(0xfffdf5);
            
            //self.topLayer.backgroundColor = CSColorFromRGB(0xfffdf5).CGColor;
            
            self.bottomLayer.backgroundColor = CSColorFromRGB(0xfffdf5).CGColor;
            
            //self.rightLayer.backgroundColor = CSColorFromRGB(0xfffdf5).CGColor;
            
            return;
        }    
    }
    
    self.topLayer.backgroundColor = BackGroundColor.CGColor;
    
    self.bottomLayer.backgroundColor = BackGroundColor.CGColor;
    
    self.rightLayer.backgroundColor = BackGroundColor.CGColor;
}

-(void)resertColor{
    
    self.backgroundColor = [UIColor whiteColor];
    
    self.bgView.backgroundColor = CSClearColor;
    
    self.topLayer.backgroundColor = BackGroundColor.CGColor;
    
    self.bottomLayer.backgroundColor = BackGroundColor.CGColor;
    
    self.rightLayer.backgroundColor = BackGroundColor.CGColor;
}


-(void)resetAllCell{
    
    [self resertColor];
    
    self.classNameLabel.text = @"";
    
    self.placeNameLabel.text = @"";
    
    self.isHaveClass = NO;
    
    [self.bgView mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.edges.mas_equalTo(self);
    }];
}

-(void)setIsTeachSelect:(BOOL)isTeachSelect{
    
    _isTeachSelect = isTeachSelect;
    
    if (isTeachSelect) {
        
        self.teachImageView.hidden = NO;
    }
    else{
        
        self.teachImageView.hidden = YES;
    }
}


/**
 设置开始日期
 */
-(void)setBeginMin:(int)beginMin{
    
    
    [self.bgView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self).offset(beginMin);
        
        make.left.width.bottom.mas_equalTo(self);
    }];
}

/**
 设置结束日期
 */
-(void)setEndMin:(int)endMin{
    
    if (endMin <= 0) {
        
        [self.bgView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.edges.mas_equalTo(self);
        }];
    }
    else{
        
        [self.bgView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(self);
            
            make.left.width.mas_equalTo(self);
            
            make.height.mas_equalTo(endMin);
        }];
    }
    
}

-(void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
